Skip to main content

Sorting I ✔

  1. Selection Sort
    • Left Portion is sorted, right portion is unsorted
    • Find minimum element of unsorted array
    • Replace the minimum element with the first item which become the last item of sorted array
    • Prevent swap if they are both
  2. Bubble Sort
  3. Insertion Sort
    1. 10 April, 2026: 00.09.19 ❌
      • Failed at implmentation
        • First item is consider as sorted.
        • Right portion from second item is consider as unsorted.
        • Inner loop: find out where the insertion should be placed for the first item of unsorted portion
          • Iterate from last item to lesser item of sorted portion

          • Instead of swapping, perform shifting operation

            StepKeyCompared WithAction TakenArray State
            138Shift 8 right[8, 8, 1, 7, 0, 10, 2]
            Insert 3 at position 0[3, 8, 1, 7, 0, 10, 2]
            218Shift 8 right[3, 8, 8, 7, 0, 10, 2]
            3Shift 3 right[3, 3, 8, 7, 0, 10, 2]
            Insert 1 at position 0[1, 3, 8, 7, 0, 10, 2]
            378Shift 8 right[1, 3, 8, 8, 0, 10, 2]
            3Stop (3 < 7)
            Insert 7 at position 2[1, 3, 7, 8, 0, 10, 2]
            408Shift 8 right[1, 3, 7, 8, 8, 10, 2]
            7Shift 7 right[1, 3, 7, 7, 8, 10, 2]
            3Shift 3 right[1, 3, 3, 7, 8, 10, 2]
            1Shift 1 right[1, 1, 3, 7, 8, 10, 2]
            Insert 0 at position 0[0, 1, 3, 7, 8, 10, 2]
            5108Stop (8 < 10)
            No shift, stays in place[0, 1, 3, 7, 8, 10, 2]
            6210Shift 10 right[0, 1, 3, 7, 8, 10, 10]
            8Shift 8 right[0, 1, 3, 7, 8, 8, 10]
            7Shift 7 right[0, 1, 3, 7, 7, 8, 10]
            3Shift 3 right[0, 1, 3, 3, 7, 8, 10]
            1Stop (1 < 2)
            Insert 2 at position 2[0, 1, 2, 3, 7, 8, 10]